package com.tenton.config;

import org.springframework.context.annotation.Bean;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * @Date: 2021/1/9
 * @Author: Tenton
 * @Description: Swagger配置文件
 */
@WebAppConfiguration
@EnableWebMvc
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket myDocket() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                //指明controller所在的包
                .apis(RequestHandlerSelectors.basePackage("com.tenton.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 构建 api文档的信息
     *
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 设置页面标题
                .title("Small Market Management System Api")
                // 设置联系人
                .contact(new Contact("Tenton", "see more at..", "923004696@qq.com"))
                // 描述
                .description("Small Market Management System SwaggerApi")
                // 定义版本号
                .version("2.0")
                .build();
    }
}